package com.sunlands.zlcx.usercenter.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sunlands.zlcx.usercenter.domain.TargetDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel("目标")
public class TargetVO implements Serializable {

    private static final long serialVersionUID = 677373656550501129L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ApiModelProperty(position = 10, value = "目标名称")
    private String targetName;

    @ApiModelProperty(position = 20, value = "父id,目标大类")
    private Long parentId;

    @ApiModelProperty(position = 20, value = "父名称")
    private String parentName;

    /**
     * 状态
     */
    @ApiModelProperty(value = "状态")
    private Integer status;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "更新时间")
    private Date updateTime;

    @ApiModelProperty(value = "排序")
    private Integer orders;

    public static TargetVO from(TargetDO targetDO) {
        return Objects.isNull(targetDO)? null : TargetVO.builder().id(targetDO.getId())
                .targetName(targetDO.getTargetName())
                .parentId(targetDO.getParentId())
                .parentName(targetDO.getParentName())
                .createTime(targetDO.getCreateTime())
                .updateTime(targetDO.getUpdateTime())
                .status(targetDO.getStatus())
                .build();
    }

}
